/**
 * Copyright (C), 2001-2031, www.bosssof.com.cn
 * FileName: Enum.java
 * Author: YuXingZh
 * Date: 16/5/2024 上午10:42
 * Description:
 * <p>
 * History:
 * Date          Author   Version  Desc
 * 2024-01-01    bosssoft  1.0.0   initialize this file
 */
package org.boss.client;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.boss.exception.ConnectException;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import static org.boss.cont.CmdCont.LOCAL_PORT;
import static org.boss.exception.BizCodeEnum.CONNECTION_ESTABLISHMENT_ERROR;

/**
 * @className: FileClient
 * @description: 客户端类
 * @author: YuXingZh
 * @date: 16/5/2024上午10:42
 * @since 1.0
 **/
public class FileClient {

    private static final String LOCAL_PORT = "localhost";

    public static void main(String[] args) throws  Exception{

        EventLoopGroup eventLoopGroup = new NioEventLoopGroup();

        try {
            Bootstrap bootstrap = new Bootstrap();
            bootstrap.group(eventLoopGroup).channel(NioSocketChannel.class).
                    handler(new FileClientInitializer());

            // 建立端口连接
            Channel channel = bootstrap.connect(LOCAL_PORT,18899).sync().channel();
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            for(;;){
                channel.writeAndFlush(br.readLine()+"\r\n");
            }
        }finally {
            eventLoopGroup.shutdownGracefully();
        }
    }
}

